using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Markup;
using Common;
using Common.Enum;
using SProject;
using SSettings;

namespace MainView.Windows
{
	public partial class ProjectReportWindow : Window, IComponentConnector
	{
		private ProjectReportSetting setting;

		private PrintSetting printSetting;

		public List<string> ListReport { get; set; }

		public List<KeyValuePair> StyleList { get; set; }

		public ProjectReportWindow()
		{
			ListReport = new List<string> { string.Empty };
			string[] files = Directory.GetFiles(Utility.GetReportTemplatePath(), "*.docx");
			string[] array = files;
			foreach (string path in array)
			{
				if ((File.GetAttributes(path) & FileAttributes.Hidden) != FileAttributes.Hidden)
				{
					ListReport.Add(Path.GetFileName(path));
				}
			}
			StyleList = new List<KeyValuePair>();
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.None,
				Value = Utility.GetMessage("sign_None")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.Circle,
				Value = Utility.GetMessage("sign_Circle")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.Square,
				Value = Utility.GetMessage("sign_Square")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.Triangle,
				Value = Utility.GetMessage("sign_Triangle")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.X,
				Value = Utility.GetMessage("sign_X")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.Dotted,
				Value = Utility.GetMessage("sign_dot")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.Dashed,
				Value = Utility.GetMessage("sign_dash")
			});
			StyleList.Add(new KeyValuePair
			{
				Key = ESeriesType.DashDot,
				Value = Utility.GetMessage("sign_dashdot")
			});
			InitializeComponent();
			setting = ConfigSettings.GetInstance().ProjectReportSetting.Clone();
			for (int num = setting.ProjectReportList.Count - 1; num >= 0; num--)
			{
				KeyValuePair kv = setting.ProjectReportList[num];
				Project project = ProjectManage.GetInstance().AllProjectList.Where((Project s) => s.BasicInfo.Name == kv.Key.ToString()).FirstOrDefault();
				if (project == null)
				{
					setting.ProjectReportList.RemoveAt(num);
				}
			}
			foreach (Project allProject in ProjectManage.GetInstance().AllProjectList)
			{
				if (setting.GetProjectReport(allProject.BasicInfo.Name) == null)
				{
					setting.SetProjectReport(allProject.BasicInfo.Name, string.Empty);
				}
			}
			printSetting = ConfigSettings.GetInstance().PrintSetting.Clone();
			tbHospitalName.DataContext = setting;
			tabItemProjectReport.DataContext = setting;
			tabItemPrintSetting.DataContext = printSetting;
		}

		private void btnOK_Click(object sender, RoutedEventArgs e)
		{
			ConfigSettings.GetInstance().ProjectReportSetting = setting;
			ConfigSettings.GetInstance().PrintSetting = printSetting;
			base.DialogResult = true;
			Close();
		}

		private void btnCancel_Click(object sender, RoutedEventArgs e)
		{
			Close();
		}
	}
}
